package myoa.permission

class ControllerNameObj {
    String name
    boolean partActionAllowed
    boolean allActionAllowed
    List<ActionNameObj> actionNameObjList

    ControllerNameObj(String controllerName, List<String> actionNameList) {
        this.name = controllerName

        actionNameObjList = []
        actionNameList.each { actionName ->
            actionNameObjList << new ActionNameObj(controllerName, actionName)
        }
    }

    String toString() {
        return name
    }

    void setAllActionAllowed(boolean b) {
        allActionAllowed = b
        synCon2Act()
    }

    /**
     * if all action.allowed = true make allActionAllowed = true
     */
    void synAct2Con() {
        def allowedActions = actionNameObjList.findAll { it.allowed }
        allActionAllowed = (actionNameObjList.size() == allowedActions.size())
    }

    /**
     * if allActionAllowed=true make all action.allowed = true
     */
    void synCon2Act() {
        if (allActionAllowed) {
            actionNameObjList.each {
                it.allowed = true
            }
        }
    }
}
